<link type="text/css" rel="stylesheet" href="http://www.12301.cc/tpl/publish_coupons/css/publish_coupons.css" />
<link rel="stylesheet" href="http://www.12301.cc/css/common/www.12301.cc.global.css"/>
<script type="text/javascript" src="http://www.12301.cc/js/global/www.12301.cc.global.js"></script>
<div class="conmone" id="conmone">
	<ul id="tabHead" class="tabHead clearfix">
        <li class="profit">发布优惠券</li>
    </ul>
	<form id="conpu_form">
		<div class="coupons_con">
			<input type="hidden" name="action" value="coupon_create">
			<div class="_dname">
				<span class="coupons_dname">名称：</span>
				<input type="text" name="coupon_name" class="coupons_title coupon_dname" value="">
			</div>
			<div class="_dname">
				<span class="coupons_dname">面额：</span>
				<input type="text" name="coupon_value" class="coupons_title coupon_num" value="">
			</div>
			<div class="_dname"> 
				<span class="coupons_dname" id="counter-time">有效期：</span>
				<div class="coup_select">
					<input type="radio" name="e_type" value="1" class="coupons_che coupon_time" checked="checked" />
				</div>
				<div class="conmone_time">
					<input type="text" data-t="bt" id="txtStartTime"  name="effective_start" data-msg="请选择时间段" class="texbettime" autocomplete="off"/> 至
					<input type="text" data-t="et" id="txtEndTime"  name="effective_end" data-msg="请选择时间段" class="texendtime" autocomplete="off"/>
					<i class="calendarBtn c1"></i>
					<i class="calendarBtn c2"></i>
				</div>
				<div class="coup_select">
					<label>
						<input type="radio" name="e_type" value="0" class="coupons_che coupon_today"  />
						<span class="coup_titile">获得优惠券当日有效</span>
					</label>
				</div>
			</div>
			<div class="_dname">
				<span class="coupons_dname_t">适用产品：</span>
				<div class="seamles">
					<span class="select_btn btn_choose">选择</span>
					<input type="hidden"  name="pid" class="select_ic" value="">
					<input type="hidden" id="Text1" value="">
				</div>
				<!-- <div class="seamlet">
					<p class="select_t">适用所有产品</p>
					<p class="select_t">选择部分产品时，最多列出两行产品，逗号隔开</p>
				</div> -->
			</div>
			<div class="_dname">
				<span class="coupons_dname"> 销售渠道：</span>
				<div class="conf_list">
					<ul class="selectlist">
						<label><li><input class="check a1" name="use_channel[]" type="checkbox" value="1">微信</li></label>
						<label><li><input class="check a2" name="use_channel[]" type="checkbox" value="2">二级店铺</li></label>
						<label><li><input class="check a3" name="use_channel[]" type="checkbox" value="3">自助机</li></label>
						<span class="conf_tt">（可多选）</span>
					</ul>
				</div>
			</div>
			<div class="_dname">
				<span class="coupons_dname">消费限制：</span>
				<div class="coupos_limit">
					<span class="font">消费满</span>
					<input type="text" class="money_coupos" name="condition" value="">
					<span class="font">&nbsp;元可用</span>
					
				</div>
			</div>
			<div class="_dname">
				<span class="coupons_dname">使用限制：</span>
				<div class="conf_list">
					<ul class="selectlist">
						<label><li><input class="check a1" name="use_limit" type="radio" value="1">不限</li></label>
						<label><li><input class="check a2" name="use_limit" type="radio" value="2">一张</li></label>
						<label><li><input class="check a3" name="use_limit" type="radio" value="3">订票数</li></label>
					</ul>
				</div>
			</div>
			<span class="line"></span>
			<!-- <div class="_dname">
					<span class="coupons_dname">发行方式：</span>
					<select name="coupos_type" id="conSelect" class="coupons_se">
						<option value="1">领取</option>
						<option value="2">派发</option> 
					</select>
			</div> -->
			<div class="_dname"> 
				<span class="coupons_dname" >领取期限：</span>
				<div class="conmone_time_">
					<input type="text" data-t="bt" id="txtStartTime_"  name="collect_startdate" data-msg="请选择时间段" class="texbettime_" autocomplete="off"/> 至
					<input type="text" data-t="et" id="txtEndTime_"  name="collect_enddate" data-msg="请选择时间段" class="texendtime_" autocomplete="off"/>
					<i class="calendarBtn c1_"></i>
					<i class="calendarBtn c2_"></i>
				</div>
			</div>
			<div class="_dname">
				<span class="coupons_dname">发行数量：</span>
				<input type="text" class="coupons_title coupon_num_ticket" name="nums" value="">
			</div>
			<!-- <div class="_dname">
				<span class="coupons_dname">领取限制：</span>
				<div>
					<label class="labela">
						<input type="radio" name="confirm_wx" value="0" class="confirm_" checked="checked">
						<input type="text" class="label_ticke"  name="conf_peo" value="">
						<span class="label_ti">张/人</span>
					</label>
					<label class="labelb">
						<input type="radio" name="confirm_wx" value="1" class="confirm_wx">
						<input type="text" class="label_people" name="conf_day" value="">
						<span class="label_ti">张/天/人</span>
					</label> 
				</div>
			</div> -->
		</div>
	</form>
	<span class="save_btn">发布</span>
</div>
<div class="bgbox">	</div>
<div class="checkchoose_box " id="checkchoose_box">
		<div class="theme_top">
			<p class="ticket_name_ch">适用产品</p>
		</div>
		<div class="theme_select">
			<!-- <label class="labeld">
				<input type="radio" name="chose_" value="0" class="chose_all" checked="checked">
				<span class="theme_t">所以产品</span>
			</label> -->
			<label class="labeld">
				<input type="radio" name="chose_" value="1" class="chose_se" checked="checked">
				<span class="theme_t">选择产品</span>
			</label> 
		</div>
		<div class="selectbox">
			<ul id="prods_list" class="ul_list">
				<ul id="selected_lnk_prods"></ul>
			</ul>
		</div>
		<div class="sereize">
			<div class="qunaer_select qunaer_type" id="qunaer_select">
				<input id="prodSearchInp" class="prodSearchInp"  type="text"></input>
				<i class="iconfont select_icon">&#xe633;</i>
				<ul class="prodList" id="prodList"></ul>
				<div class="searchmsg"><span class="no_seach">无结果</span></div>
				<input type="hidden"  id="lid_id" value=""/>
				<div class="qunaer_table">
					<div class="tbBox">	</div> 
				</div>
			</div>
			
			<div class="order_div" id="order_lili">
				<ul class="order_ul"></ul>
			</div>
		</div>
		<div class="btnbox">
			<span class="btn_base btn_cancels">取消</span>
			<span class="btn_base sure_s btn_sure_all" >确定</span>
		</div>
</div>
<script type="text/javascript" src="http://www.12301.cc/tpl/prod_sale/js/class.js"></script>
<script type="text/javascript" src="http://wx.12301.cc/public/js/common/ajax.js"></script>
<script type="text/javascript" src="http://www.12301.cc/tpl/publish_coupons/js/publish_coupons.js"></script>
<script src="http://www.12301.cc/js/WdatePicker.js"></script>
<script id="list_template" type="text/template">
	<li class="list">
		{title}<a class="rm" title="删除" href="javascript:;">X</a>
		<input type="hidden" name="lnkprods[]" value="{id}">
	</li>
</script>
<script>
 
var lnk_prods_opt = {
	
    showDialog : function(){
        
		// $.ajax({
			    // "url" : "http://www.12301.cc/tpl/zbar2.html",
				// "data" :  {action:'land_search'},
				// "dataType":"json",
				// "type": 'POST', 
				// "success":function(data){
					// var contents="";
					// var list = data.list;
						// for(var i in list){
						// var id =list[i]["id"];
						// var keywords =list[i]["ltitle"];
						// contents=contents+"<li title="+keywords+" data-id="+id+" class=\"add_list\">"+keywords+"</li>";
						// }
						// $(".order_ul").html(contents); 
					// }          
			// });
			// $(".add_list").live("click",function(){
				// var  tpl = $("#list_template").html();
				// $("#selected_lnk_prods").empty();
					// var id = $(this).attr("data-id");
					// console.log(id)
					// var k = $(this).text();
					// var lig = $(".ul_list li").length;
					// if(lnk_prods_opt.check(id)){
						  // $("#selected_lnk_prods").after(template(tpl, {id:id,title:k}));
					// }
					 // else{
						// PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">您已添加了同样的产品</p>');
					 // }	
					
			// })
			
		//$("#mask").css("display","block")
    },
	chlick : function(){
				var  tpl = $("#list_template").html();
				$("#selected_lnk_prods").empty();
					//var k = $(this).text();
					var kk = $(this).attr("title");
					var tttile = $(this).attr("tttile");
					var k = kk+"-"+tttile;
					var lig = $(".ul_list li").length;
					var id = $(this).attr("data-id");
					if(lnk_prods_opt.check(id)){
						  $("#selected_lnk_prods").after(template(tpl, {id:id,title:k}));
					}
					 else{
						PFT_GLOBAL.U.Alert("fail",'<p style="width:240px">您已添加了同样的产品</p>');
					 }	
					
			},
	check : function(id){
		var re = true;
		$(".ul_list li input").each(function(){
			var data = $(this).val();
				if(id==data){
					re = false;
				}
		})
		return re;
	},
	clikkk :function(){
		var sel="";
		$(".ul_list li input").each(function(){		
			sel+= ","+$(this).val();  
			$(".select_ic").val(sel)    
			
		})
		
	},
	add_list : function(){
		lnk_prods_opt.clikkk()
		$("#checkchoose_box").animate({"top":-100});			
		$(".bgbox,#checkchoose_box").hide();
		var s = $(".select_ic").val();
		if (s.substr(0,1)==',') 
		s=s.substr(1);
		$(".select_ic").val(s)
	}
};
function template(tpl, val){
				return tpl.replace(/\{(\w+)\}/g, function(m,i){
					if(val[i]) {
						return val[i];
					} else {
						return '';
					}
				})
			};
$(".rm").live('click',function(e){
	$(this).parent().remove();
	var v = $(this).next('input').val();
	$("input[name='lnkprods'][value='"+v+"']").remove();
})

var sel="";
$(".btn_sure_allk").on('click',function(e){
	$(".ul_list li input").each(function(i){		
			
			sel+= $(this).val()+",";  
			//$(".select_ic").val(null);
			$(".select_ic").val(sel)
			$("#checkchoose_box").animate({"top":-100});			
			$(".bgbox,#checkchoose_box").hide();
			//$(this).val(null);
			
		})
}) 
jQuery(document).ready(function($){
     $(".btn_choose").on('click', lnk_prods_opt.showDialog);
     $(".add_list").live('click', lnk_prods_opt.chlick);
     $(".btn_sure_all").on('click', lnk_prods_opt.add_list);
	

});

</script>
<script>
$("#txtStartTime").bind("click focus", function () {             
   var endtimeTf = $dp.$('txtEndTime');             
   WdatePicker({                            
	   maxDate: '#F{$dp.$D(\'txtEndTime\')}',      
	   dateFmt: "yyyy-MM-dd HH:mm:ss",              
	   onpicked: function () { endtimeTf.focus(); }          
		});  
	$(".coupon_time").attr("checked","checked");
   });          
$("#txtEndTime").bind("click focus", function () {       
		WdatePicker({           
		   minDate: '#F{$dp.$D(\'txtStartTime\')}', 
		   dateFmt: "yyyy-MM-dd HH:mm:ss"       
	   });  
	$(".coupon_time").attr("checked","checked");
   });
$("#txtStartTime_").bind("click focus", function () {             
   var endtimeTf = $dp.$('txtEndTime_');             
   WdatePicker({                            
	   maxDate: '#F{$dp.$D(\'txtEndTime_\')}',      
	   dateFmt: "yyyy-MM-dd HH:mm:ss",              
	   onpicked: function () { endtimeTf.focus(); }          
		});         
   });          
$("#txtEndTime_").bind("click focus", function () {       
		WdatePicker({           
		   minDate: '#F{$dp.$D(\'txtStartTime_\')}', 
		   dateFmt: "yyyy-MM-dd HH:mm:ss"       
	   });         
   });
  
   

(function(){
	var h=$(window).height(); 
	var w=$(window).width(); 
	$(".btn_choose").on("click",function(e){
		var target = $(e.currentTarget);
		var tpl = $("#list_template").html();
		var atpl = $("#list_tema").html();
		var teacl = target.attr("data");
		var tlid = target.attr("lid");
		$(".terminal_add").attr("add",teacl);
		$(".terminal_add").attr("lid",tlid);
		var ttitle = target.attr("title");
		$(".ticket_name_ch").text(ttitle);
		$(".bgbox").show();
		$("#checkchoose_box").show();
		$("#checkchoose_box").animate({"top":100});
		$(".bgbox").css("height",h);
		$(".bgbox").css("width",w); 
		
		})
		
		$(".btn_cancels,.close_btn").on("click",function(e){
			var target = $(e.currentTarget);
			$("#checkchoose_box").animate({"top":-100});			
			$(".bgbox,#checkchoose_box").hide();				
		});
})();
</script>